package hot_100;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class 全排列 {
    public static void main(String[] args) {

    }

    int n;
    List<List<Integer>> ans = new ArrayList<>();
    List<Integer> numss  = new ArrayList<>();

    public List<List<Integer>> permute(int[] nums) {
        for (int num : nums) {
            numss.add(num);
        }
        n = nums.length;
        Dfs(0);
        return ans;
    }

    public void Dfs(int x) {
        if (x >= n - 1) {
            ans.add(new ArrayList<>(numss));
            return;
        }
        for (int i = x; i < n; i++) {
            Collections.swap(numss, i, x);
            Dfs(x + 1);
            Collections.swap(numss, i, x);
        }
    }
}
